package com.qpkj.web.controller.oms;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.qpkj.common.annotation.Log;
import com.qpkj.common.core.controller.BaseController;
import com.qpkj.common.core.domain.AjaxResult;
import com.qpkj.common.enums.BusinessType;
import com.qpkj.oms.domain.OmsTaskRemark;
import com.qpkj.oms.service.IOmsTaskRemarkService;
import com.qpkj.common.utils.poi.ExcelUtil;
import com.qpkj.common.core.page.TableDataInfo;

/**
 * 任务备注Controller
 *
 * @author ruoyi
 * @date 2022-12-24
 */
@RestController
@RequestMapping("/oms/taskremark")
public class OmsTaskRemarkController extends BaseController {
    @Autowired
    private IOmsTaskRemarkService omsTaskRemarkService;

    /**
     * 查询任务备注列表
     */
   // @PreAuthorize("@ss.hasPermi('oms:taskremark:list')")
    @GetMapping("/list")
    public TableDataInfo list(OmsTaskRemark omsTaskRemark) {
        startPage();
        List<OmsTaskRemark> list = omsTaskRemarkService.selectOmsTaskRemarkList(omsTaskRemark);
        return getDataTable(list);
    }

    /**
     * 导出任务备注列表
     */
    @PreAuthorize("@ss.hasPermi('oms:taskremark:export')")
    @Log(title = "任务备注", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OmsTaskRemark omsTaskRemark) {
        List<OmsTaskRemark> list = omsTaskRemarkService.selectOmsTaskRemarkList(omsTaskRemark);
        ExcelUtil<OmsTaskRemark> util = new ExcelUtil<OmsTaskRemark>(OmsTaskRemark.class);
        util.exportExcel(response, list, "任务备注数据");
    }

    /**
     * 获取任务备注详细信息
     */
    @PreAuthorize("@ss.hasPermi('oms:taskremark:query')")
    @GetMapping(value = "/{remarkId}")
    public AjaxResult getInfo(@PathVariable("remarkId") Long remarkId) {
        return success(omsTaskRemarkService.selectOmsTaskRemarkByRemarkId(remarkId));
    }

    /**
     * 新增任务备注
     */
   // @PreAuthorize("@ss.hasPermi('oms:taskremark:add')")
    @Log(title = "任务备注", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OmsTaskRemark omsTaskRemark) {
        omsTaskRemark.setRemarkUser(getUsername());
        omsTaskRemark.setUserId(getUserId());
        omsTaskRemark.setRemarkTime(new Date());
        return toAjax(omsTaskRemarkService.insertOmsTaskRemark(omsTaskRemark));
    }

    /**
     * 修改任务备注
     */
    //@PreAuthorize("@ss.hasPermi('oms:taskremark:edit')")
    @Log(title = "任务备注", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OmsTaskRemark omsTaskRemark) {
        if (!omsTaskRemark.getUserId().equals(getUserId())) {
            return error("不能修改其他用户的备注!");
        }
        return toAjax(omsTaskRemarkService.updateOmsTaskRemark(omsTaskRemark));
    }

    /**
     * 删除任务备注
     */
   // @PreAuthorize("@ss.hasPermi('oms:taskremark:remove')")
    @Log(title = "任务备注", businessType = BusinessType.DELETE)
    @DeleteMapping("/{remarkIds}")
    public AjaxResult remove(@PathVariable Long[] remarkIds) {
        return toAjax(omsTaskRemarkService.deleteOmsTaskRemarkByRemarkIds(remarkIds));
    }
}
